package com.wm.task2.dao;

import com.wm.task2.util.CreateId;
import com.wm.task2.util.ManageFile;
import com.wm.task2.vo.Account;

public class UserDAOFile {
    Account account = new Account();
    private String path = "D:/java/study/test/BBS/";

    public Account register(String name, String passWord) {//注册
        account.setName(name);
        account.setPassWord(passWord);
        account.setAccountNum(String.valueOf( CreateId.getId()));
        String data = name + "\n" + account.getAccountNum() + "\n" + passWord + "\n";

        ManageFile.writerFile(path + account.getAccountNum() + ".txt", data, true);
        return account;
    }

    public Account login(String id, String passWord) {//登录
        String[] str = ManageFile.readFile(path + id + ".txt").split("\n");
        if(str[0].isEmpty()||!passWord.equals(str[2])) {
            return null;
        }
        account.setName(str[0]);
        account.setAccountNum(str[1]);
        account.setPassWord(str[2]);
        return account;
    }
}
